package com.epfresh.supplier.entity;

import com.epfresh.api.utils.DateUtil;
import com.epfresh.api.utils.FormatUtil;

import java.util.List;

/**
 * @author wangzhanghuan
 * @version 1.0
 * @date create 17-5-19
 * @Description
 */

public class Promotion {

    /*
     "id":111,          //修改的时候有
            "productSpecId":3370,//商品id
            "price":2, //促销价格
            "quantityPerAccount":100,//限购数量
            "totalQuantity":10000,//促销总数量
            "beginTime":"2017-07-01",
            "endTime":"2017-07-07",
            "markId":1, //取选中图片spikeMark或者promotionMark的id
            "type":1,  // 1促销2秒杀
            "spikeTime": [                   //秒杀场次，促销不填
                    "08:00-10:00",
                    "14:00-16:00"
                ]


{
  "id": 18,
  "totalQuantity": 1.0,
  "quantityPerAccount": 2.04,
  "price": 1.0,
  "originalCost ": 84.71,
  "promotionItem": [
    {
      "beginTime": "",
      "endTime": "",
      "salesVolume": 0.00
    }
  ],
  "beginTime": "2017-05-22",
  "type": 1,
  "endTime": "2017-05-29",
  "chargeUnit": "公斤"
}

    * */

    private String moq;

    public String getMoq() {
        return moq;
    }

    public void setMoq(String moq) {
        this.moq = moq;
    }

    private String id;
    private String price;
    private String productSpecId;
    private String quantityPerAccount;
    private String totalQuantity;
    private String beginTime;
    private String endTime;
    private String type;
    private String markId;
    private String overStatus;
    //1,不能改
    private String promotionStatus;
    private String originalCost;
//    private String originalPrice;
    private String chargeUnit;
    private List<String> spikeTime;
    private List<PromotionItem> promotionItem;
    private String storeId;

    public String getStoreId() {
        return storeId;
    }

    public void setStoreId(String storeId) {
        this.storeId = storeId;
    }

    //    public String getOriginalPrice() {
//        return originalPrice;
//    }
//
//    public void setOriginalPrice(String originalPrice) {
//        this.originalPrice = originalPrice;
//    }


    public String getPromotionStatus() {
        return promotionStatus;
    }

    public void setPromotionStatus(String promotionStatus) {
        this.promotionStatus = promotionStatus;
    }

    public boolean isOverStatus(){
        return !"1".equals(overStatus);
    }
    public String getOverStatus() {
        return overStatus;
    }

    public void setOverStatus(String overStatus) {
        this.overStatus = overStatus;
    }

    public String getOriginalCost() {
        return originalCost == null ?"" : originalCost;
    }

    public void setOriginalCost(String originalCost) {
        this.originalCost = originalCost;
    }

    public String getChargeUnit() {
        return chargeUnit;
    }

    public void setChargeUnit(String chargeUnit) {
        this.chargeUnit = chargeUnit;
    }

    public List<PromotionItem> getPromotionItem() {
        return promotionItem;
    }

    public void setPromotionItem(List<PromotionItem> promotionItem) {
        this.promotionItem = promotionItem;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getProductSpecId() {
        return productSpecId;
    }

    public void setProductSpecId(String productSpecId) {
        this.productSpecId = productSpecId;
    }

    public String getQuantityPerAccount() {
        return quantityPerAccount;
    }

    public void setQuantityPerAccount(String quantityPerAccount) {
        this.quantityPerAccount = quantityPerAccount;
    }

    public String getTotalQuantity() {
        return totalQuantity;
    }

    public void setTotalQuantity(String totalQuantity) {
        this.totalQuantity = totalQuantity;
    }

    public String getBeginTime() {
        return beginTime;
    }

    public void setBeginTime(String beginTime) {
        this.beginTime = beginTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMarkId() {
        return markId;
    }

    public void setMarkId(String markId) {
        this.markId = markId;
    }

    public List<String> getSpikeTime() {
        return spikeTime;
    }

    public void setSpikeTime(List<String> spikeTime) {
        this.spikeTime = spikeTime;
    }

    public String getPromotionTime() {



//        String s = beginTime+"-"+endTime;
//        return DateUtil.getPromotionDate(beginTime,endTime);
        return DateUtil.getPromotionDate(beginTime,endTime);
    }
    public String getSecKillAmount() {
        StringBuilder sb = new StringBuilder();
        if (promotionItem != null){
            for (int i=0;i<promotionItem.size();i++){
                PromotionItem promotionItem = this.promotionItem.get(i);
                String s = promotionItem.getSalesVolume();
                String s2 = promotionItem.getTotalQuantity();
                if (s != null &&  !"".equals(s)){
                    s = FormatUtil.subZeroAndDot(s);
                }
                String s1 = promotionItem.getBeginTime() + "-" + promotionItem.getEndTime() + "  秒杀数量" + s + "/" + s2 + chargeUnit;


                //已结束
                if ("0".equals(promotionItem.getOverItemStatus())){
                    s1 += " (已结束)";
                }else {

                }
                if (i != 0){
                    sb.append("\n");
                }
                sb.append(s1);
            }
        }
        return sb.toString();
    }
    public String getLimitStr() {
        StringBuilder sb = new StringBuilder();
        if (promotionItem != null && promotionItem.size() > 0) {

            PromotionItem promotionItem = this.promotionItem.get(0);
            String s2 = promotionItem.getTotalQuantity();
            String s = promotionItem.getSalesVolume();
            if (s != null && !"".equals(s)) {
                s = FormatUtil.subZeroAndDot(s);
            }
            String s1 = "促销数量" + s + "/" + s2 + chargeUnit;

            sb.append(s1);

        } else {
            String s2 = "促销数量" + 0 + "/" + totalQuantity + chargeUnit;
            sb.append(s2);
        }
        return sb.toString();
    }
    public void cloneData(Promotion p) {

        if (p != null) {
            id = p.getId();
            price = p.getPrice();
            productSpecId = p.getProductSpecId();
            quantityPerAccount = p.getQuantityPerAccount();
            totalQuantity = p.getTotalQuantity();
            beginTime = p.getBeginTime();
            endTime = p.getEndTime();
            type = p.getType();
            markId = p.getMarkId();
            spikeTime = p.getSpikeTime();
        }

    }

    @Override
    public String toString() {
        return "Promotion{" +
                "id='" + id + '\'' +
                ", price='" + price + '\'' +
                ", productSpecId='" + productSpecId + '\'' +
                ", quantityPerAccount='" + quantityPerAccount + '\'' +
                ", totalQuantity='" + totalQuantity + '\'' +
                ", beginTime='" + beginTime + '\'' +
                ", endTime='" + endTime + '\'' +
                ", type='" + type + '\'' +
                ", markId='" + markId + '\'' +
                ", originalCost='" + originalCost + '\'' +
                ", chargeUnit='" + chargeUnit + '\'' +
                ", spikeTime=" + spikeTime +
                ", promotionItem=" + promotionItem +
                '}';
    }
}
